test: point doc tests to the main library, for cyclic deps.
authorHuon Wilson <dbau.pp+github@gmail.com>
Sat, 6 Jun 2015 08:22:36 +0000 (18:22 +1000)
committerHuon Wilson <dbau.pp+github@gmail.com>
Sat, 6 Jun 2015 08:22:36 +0000 (18:22 +1000)
Previously a dependency cycle like `a` <-(normal)- `b` <-(dev)- `a`
would mean that importing `b` in `a`'s doc test would fail because the
original `a` library was not found.

Fixes #1686.

src/cargo/ops/cargo_test.rs
tests/test_cargo_test.rs

index 631ffae52a2492b678d98765cec1305553a1eea3..a911058fbe2e89e891cf79af2673b8c009a8cba4 100644 (file)
@@ -38,13 +38,13 @@ pub fn run_tests(manifest_path: &Path,
         let mut p = try!(compile.rustdoc_process(&compile.package));
         p.arg("--test").arg(lib)
          .arg("--crate-name").arg(&crate_name)
-         .arg("-L").arg(&{
-             let mut arg = OsString::from("dependency=");
-             arg.push(&compile.deps_output);
-             arg
-         })
          .cwd(compile.package.root());
 
+        for &rust_dep in &[&compile.deps_output, &compile.root_output] {
+            let mut arg = OsString::from("dependency=");
+            arg.push(rust_dep);
+            p.arg("-L").arg(arg);
+        }
         for native_dep in compile.native_dirs.values() {
             p.arg("-L").arg(native_dep);
         }
index 0b6e21c3ccff327f02c9d523db44b7864aa9c7ae..53489031362e2d2467a1467ba189be659ebc94f9 100644 (file)
@@ -1582,3 +1582,51 @@ test!(dylib_doctest2 {
     assert_that(p.cargo_process("test"),
                 execs().with_stdout(""));
 });
+
+test!(cyclic_dev_dep_doc_test {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [dev-dependencies]
+            bar = { path = "bar" }
+        "#)
+        .file("src/lib.rs", r#"
+            //! ```
+            //! extern crate bar;
+            //! ```
+        "#)
+        .file("bar/Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            foo = { path = ".." }
+        "#)
+        .file("bar/src/lib.rs", r#"
+            extern crate foo;
+        "#);
+    assert_that(p.cargo_process("test"),
+                execs().with_stdout(format!("\
+{compiling} foo v0.0.1 ([..])
+{compiling} bar v0.0.1 ([..])
+{running} target[..]foo[..]
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+
+{doctest} foo
+
+running 1 test
+test _0 ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
+
+", compiling = COMPILING, running = RUNNING, doctest = DOCTEST)))
+});